var ABCArray = ["A","B","C","D","E","F","G","H","I","J"];

function displayRecap() {
	$('#content').html(recapHTML);
	$('#recap_end').click(endQCMClickHandler);	
	displayRecapAnswers();
}

function displayRecapAnswers() {
	$.each(qcmDATA.sections, function(key, section) {
		$.each(section.questions, function(key, question) {
					$('#recap_answers').append(recapAnswerHTML);
					$('.recap_answer:last-child').attr('id', 'question_' + question.id);
					$('#question_' + question.id + ' .question_title').html(question.statement);
					
					var isAnswered = false;
					
					$.each(results, function(key, result) {
						if(result.idQuestion == question.id) {
							$('#question_' + question.id + ' .user_results').append('&nbsp;' + ABCArray[result.num]);
							isAnswered = true;
						}
					});
					
					if(isAnswered) {
						$('#question_' + question.id + ' .answered').css('opacity', '1');
					} else {
						$('#question_' + question.id + ' .unanswered').css('opacity', '1');
					}
					
					if(question.isMarked) {
						$('#question_' + question.id + ' .marked').css('opacity', '1');
					}
					$('#question_' + question.id).click(recapQuestionClickHandler);
		});
	});
}

function recapQuestionClickHandler() {
	var tmpQuestionID = $('h3', this).parent().attr('id');
	var questionID = tmpQuestionID.split('_')[1];
	numCurrentQuestion = getQuestionNumFromID(questionID);
	localStorage['numCurrentQuestion'] = numCurrentQuestion;
	var numSection = getSectionNumFromQuestionID(questionID);
	numCurrentSection = numSection;
	localStorage["numCurrentSection"] = JSON.stringify(numCurrentSection);
	numCurrentQuestionInSection = getNumQuestionInSection(numSection, questionID);
	localStorage['numCurrentQuestionInSection'] = JSON.stringify(numCurrentQuestionInSection);
	showTest();
}


function endQCMClickHandler(){
	$.getJSON('/QCM-Server/ResultServlet?results=' + localStorage["Results"],function(data){
		//alert(data);
	});
}

